package com.example.controller;

import com.example.service.OllamaConversationService;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OllamaConversationController {

    private final OllamaConversationService conversationService;


    @Autowired
    public OllamaConversationController(OllamaConversationService conversationService) {
        this.conversationService = conversationService;
    }

    /**
     * 发起会话
     *
     * @param message
     * @return
     */
    @GetMapping("/start-conversation")
    public String startConversation(@RequestParam(defaultValue = "我叫张三") String message) {
        return conversationService.startConversation(message);
    }


    /**
     * 持续聊天
     *
     * @param sessionId
     * @param message
     * @return
     */
    @GetMapping("/continue-conversation")
    public String continueConversation(@RequestParam(defaultValue = "sessionId") String sessionId, @RequestParam(defaultValue = "我叫什么?") String message) {
        return conversationService.continueConversation(sessionId, message);
    }

    /**
     * 获取某个会话的聊天记录
     * @param sessionId
     * @return
     */
    @GetMapping("/getMessageList")
    public List<Message> getMessageList(@RequestParam(defaultValue = "sessionId") String sessionId) {
        return conversationService.getMessageList(sessionId);
    }
}